package com.wms_backend.controller;

import com.auth0.jwt.interfaces.Claim;
import com.wms_backend.entity.Inbound;
import com.wms_backend.utils.JwtUtil;
import com.alibaba.fastjson.JSONObject;
import com.wms_backend.entity.Result;
import com.wms_backend.service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;


import java.util.List;
import java.util.Map;
import java.util.Objects;

@RestController
@RequestMapping("/inventory")
public class InventoryController {


    @Autowired
    private InventoryService inventoryService;

    @PostMapping("/get-existing")
    public Result getExisting(@RequestHeader String token, @RequestBody JSONObject param) {
        Map<String, Claim> mp = JwtUtil.verifyToken(token);
        String userId = mp.get("userId").asString();
        Pageable pageable = PageRequest.of(param.getIntValue("page"), param.getIntValue("size"));
        Page<List<Map<String, Object>>> pi = inventoryService.selectExisting(userId, param, pageable);
        return Result.success(pi);
    }



    @PostMapping("/get-repository-status")
    public Result getRepositoryStatus(@RequestHeader String token,@RequestBody JSONObject param) {
        Map<String, Claim> mp = JwtUtil.verifyToken(token);
        String userId = mp.get("userId").asString();
      List<Map<String,Object>> ans = inventoryService.getRepositoryStatus(param);
      return Result.success(ans);
    }
    @PostMapping("/get-shelf-information")
    public Result getShelfGoods(@RequestHeader String token,@RequestBody JSONObject param) {
        Map<String, Claim> mp = JwtUtil.verifyToken(token);
        String userId = mp.get("userId").asString();
        List<Map<String,Object>> ans = inventoryService.getShelfGoods(param,userId);
        return Result.success(ans);
    }
    @GetMapping("/get-companyId")
    public Result getCompanyId(@RequestHeader String token) {
        Map<String, Claim> mp = JwtUtil.verifyToken(token);
        String userId = mp.get("userId").asString();
        return    inventoryService.getCompanyId(userId);

    }

}